<template>
  <home-panel ref="target" title="热门品牌" sub-title="国际经典 品质保证">
    <template v-slot:right>
      <a href="javascript:;" class="iconfont icon-angle-left" :class="{disabled: activeIndex=== 0}" @click="activeIndex=0"></a>
      <a href="javascript:;" class="iconfont icon-angle-right" :class="{disabled: activeIndex=== 1}" @click="activeIndex=1"></a>
    </template>
    <div class="box" >
      <transition name="fade">
        <ul class="list"  v-if="list.length > 0"
        :style="`transform: translateX(${activeIndex === 1 ? -50 : 0}%);`">
          <li v-for="list in list" :key="list.id">
            <router-link to="/">
              <img :src="list.picture" alt=""/>
            </router-link>
          </li>
        </ul>
        <div class="home-skeleton" v-else>
          <div class="item" v-for="i in 5" :key="i">
            <XtxSkeleton bg="#e4e4e4" width="240px" height="305px" animated />
          </div>
        </div>
      </transition>
    </div>
  </home-panel>
</template>

<script>
import HomePanel from './homePanel.vue'
import { getBrandListAPI } from '@/api'
import { useLazyData } from '@/utils/hooks'
import { ref } from 'vue'
export default {
  name: 'HomeBrand',
  components: { HomePanel },
  setup () {
    const { target, list } = useLazyData(() => getBrandListAPI({ limit: 10 }))
    // 移动
    // 下标
    const activeIndex = ref(0)
    return { activeIndex, target, list }
  }
}
</script>

<style scoped lang="less">
.home-panel {
  background: #f5f5f5;
}
.iconfont {
  width: 20px;
  height: 20px;
  background: #ccc;
  color: #fff;
  display: inline-block;
  text-align: center;
  margin-left: 5px;
  background: var(--xtx-color);
  &::before {
    font-size: 12px;
    position: relative;
    top: -2px;
  }
  &.disabled {
    background: #ccc;
    cursor: not-allowed;
  }
}
.box {
  display: flex;
  width: 100%;
  height: 345px;
  overflow: hidden;
  padding-bottom: 40px;
  .list {
    width: 200%;
    display: flex;
    transition: all 1s;
    li {
      margin-right: 10px;
      width: 240px;
      &:nth-child(5n) {
        margin-right: 0;
      }
      img {
        width: 240px;
        height: 305px;
      }
    }
  }
}

.skeleton {
  display: flex;
  .xtx-skeleton {
    margin-right: 10px;
    &:nth-child(5n) {
      margin-right: 0;
    }
  }
}
.home-skeleton {
  width: 1240px;
  height: 406px;
  display: flex;
  justify-content: space-between;
  .item {
    width: 306px;
    .xtx-skeleton ~ .xtx-skeleton {
      display: block;
      margin: 16px auto 0;
    }
  }
}
</style>
